/*
 * @Author: Dorange.Wang
 * @Date: 2021-05-29 14:10:00
 * @LastEditors: wangming
 * @LastEditTime: 2021-09-07 15:24:41
 * @Description: file content
 */
export const configMap = {
  required: 'required',
  visible: 'hide',
  disabled: 'disabled',
  hidden:'hide'
};
import {
  cloneDeep
} from 'lodash';
/**
 * 组件参数设置
 */
export function setConfig(props = {}) {
  const newPorps = {};
  Object.keys(props).forEach((prop) => {
    const key = configMap[prop];
    if (key) {
      newPorps[key] = prop === 'visiable' ? !props[prop] : props[prop];
    }
  });
  this.config.__config = Object.assign({}, this.config.__config, newPorps);
}

/**
 * 设置组件值
 */
export function setValue(value) {
  this.$emit('input', value);
  // this.datas = value
}

/**
 * 获取组件的值
 */
export function getValue() {
  return cloneDeep(this.value)
}

/**
 * 下拉选择、单选、多选组件特有
 * 重新加载刷新数据
 */
export function reload(params) {}

/**
 * 获取选中的值
 * @returns
 */
export function getSelcted() {
  return [];
}

/**
 * 设置选中
 * @param {*} keys
 */
export function setSelected(keys = []) {}

/**
 * 分组
 * 折叠/收起
 * @param {*} value
 */
export function setExpand(value) {}

/**
 * 标签页
 * 设置激活
 * @param {*} key
 */
export function setActive(key) {}

/**
 * form表单
 * 获取表单值
 */
export function getValues() {
  return cloneDeep(this.formData)
}
/**
 * form表单
 * 批量设置表单值
 */
export function setValues(values = {}) {
  for (let i in this.formData) {
    this.formData[i] = undefined
  }
  //如果values内有_VALUES_ 系统内置字段优先取系统内置字段
  let _VALUES_ = values._VALUES_ || {}
  let data = Object.assign({}, values, _VALUES_, {
    _VALUES_: undefined
  })
  for (let i in data) {
    this.$set(this.formData, i, data[i]);
  }
}